//
//  CollectTableViewCell.m
//  Hyatt
//
//  Created by 周游 on 15/5/26.
//  Copyright (c) 2015年 QC.L. All rights reserved.
//

#import "CollectTableViewCell.h"

@implementation CollectTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        [self createSubviews];
        
    }
    return self;
}

- (void)createSubviews
{
    self.backgroundColor = [UIColor grayColor];
    self.backV = [[UIView alloc] init];
    self.backV.backgroundColor = [UIColor whiteColor];
    [self addSubview:self.backV];
    
#warning 周游注 : cell先用默认高度, 再赋值自己指定高度
    // 图片
    self.headIV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"headIV"]];
    [self.backV addSubview:self.headIV];
    
    // 小标题
    self.subjectL = [[UILabel alloc] init];
    self.subjectL.numberOfLines = 0;
    [self.backV addSubview:self.subjectL];
    
    // 内容
    self.contentL = [[UILabel alloc] init];
    self.contentL.font = [UIFont systemFontOfSize:13];
    [self.backV addSubview:self.contentL];
    
    // 收藏
    self.collectB = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.collectB setTitle:@"收藏" forState:UIControlStateNormal];
    [self.collectB setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [self.backV addSubview:self.collectB];
        
}
#warning 创建公共类存放类方法
+ (CGFloat)heightForCell:(NSString *)content
{
    CGRect frame = [content boundingRectWithSize:CGSizeMake(225, 2000) options:NSStringDrawingUsesLineFragmentOrigin attributes:[NSDictionary dictionaryWithObject:[UIFont systemFontOfSize:13.0] forKey:NSFontAttributeName] context:nil];

    return frame.size.height;
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    // 背景视图
    self.backV.frame = CGRectMake(0, kInterval / 2, self.frame.size.width, self.frame.size.height - kInterval);
    
    // 图片
    self.headIV.frame = CGRectMake(kInterval, kInterval, 60, self.backV.frame.size.height  - kInterval * 2);
    // 小标题
//    self.subjectL.frame = CGRectMake(self.headIV.frame.origin.x + self.headIV.frame.size.width + kInterval, kInterval, self.frame.size.width - self.headIV.frame.origin.x - self.headIV.frame.size.width - kInterval - 30, 8);
    self.subjectL.frame = CGRectMake(self.headIV.frame.origin.x + self.headIV.frame.size.width + kInterval, kInterval, 225, 8);
    self.subjectL.text = @"段子来了";
    
    // 内容
    self.contentL.frame = CGRectMake(self.headIV.frame.origin.x + self.headIV.frame.size.width + kInterval, self.backV.frame.size.height - 15 - kInterval, self.subjectL.frame.size.width, 15);
    self.contentL.text = @"节目数276    2015-05-26更新";

    // 收藏
    self.collectB.frame = CGRectMake(self.contentL.frame.origin.x + self.contentL.frame.size.width + 10, self.contentL.frame.origin.y, 50, self.contentL.frame.size.height);
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

@end
